package com.example.iorder.util;

import java.text.DateFormatSymbols;
import java.util.Calendar;

import android.content.Context;

import com.example.iorder.R;

public class TextFormatter {
	public static String formatPrice(Context context, double price) {
		String formattedPrice = context.getResources().getString(R.string.euro_sign) + " " + Double.toString(price);
		// If the price has a decimal
		if (price % 1 != 0) {
			// Check if price has one decimal after the comma, e.g. 25,5 and make it 25,50
			double multipliedPrice = price * 10;
			if (multipliedPrice % 1 == 0) {
				formattedPrice += "0";
			}
		}
		return formattedPrice;
	}
	
	public static String formatStringForTotalPrice(Context context, double price) {
		String formattedPrice = formatPrice(context, price);
		return "Totaalbedrag: " + formattedPrice;
	}
	
	public static String getMonthAsText(int month) {
		DateFormatSymbols dfs = new DateFormatSymbols();
		dfs.setMonths(new String [] {
				"Januari",
				"Februari",
				"Maart",
				"April",
				"Mei",
				"Juni",
				"Juli",
				"Augustus",
				"September",
				"Oktober",
				"November",
				"December"
		});
		String formattedMonth = dfs.getMonths()[month];
		return formattedMonth;
	}
	
	public static String formatDateToString(Calendar selectedDate) {
		int selectedYear = selectedDate.get(Calendar.YEAR);
		int selectedMonthInt = selectedDate.get(Calendar.MONTH) + 1;
		int selectedDayInt = selectedDate.get(Calendar.DAY_OF_MONTH);
		String selectedMonth = selectedMonthInt < 10 ? "0" + selectedMonthInt : "" + selectedMonthInt; 
		String selectedDay = selectedDayInt < 10 ? "0" + selectedDayInt : "" + selectedDayInt;
		String selectedDateFormattedString = selectedYear + "-" + selectedMonth + "-" + selectedDay;
		return selectedDateFormattedString;
	}
	
	public static String formatTimeToString(Calendar selectedDate) {
		int selectedHourInt = selectedDate.get(Calendar.HOUR_OF_DAY);
		int selectedMinuteInt = selectedDate.get(Calendar.MINUTE);
		String selectedHour = selectedHourInt < 10 ? "0" + selectedHourInt : "" + selectedHourInt;
		String selectedMinute = selectedMinuteInt < 10 ? "0" + selectedMinuteInt : "" + selectedMinuteInt;
		String selectedTimeFormattedString = selectedHour + ":" + selectedMinute;
		return selectedTimeFormattedString;
	}
}
